package edu.nf.project.mappers.accountsAndPermissions.convention;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.nf.project.entitys.dto.accountsAndPermissions.MineInfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author gjh
 * @Date 2025/6/5
 * @Description: 用户端-我的
 */
@Mapper
public interface MineInfoDTOMapper extends BaseMapper<MineInfoDTO> {
    @Select("SELECT \n" +
            "    u.u_name AS 用户名,\n" +
            "    c.member_code AS 会员号,\n" +
            "    m.member_name AS 会员等级,\n" +
            "    c.point AS 积分,\n" +
            "    c.surplus AS 余额,\n" +
            "    COUNT(cic.coupon_id) AS 优惠券数量\n" +
            "FROM users u\n" +
            "JOIN customer_info c ON u.u_id = c.u_id\n" +
            "JOIN member m ON c.member_id = m.member_id\n" +
            "LEFT JOIN customer_info_coupon cic ON c.customer_id = cic.customer_id\n" +
            "WHERE u.u_id = #{t_id}\n" +
            "GROUP BY u.u_name, c.member_code, m.member_name, c.point, c.surplus;\n")
    MineInfoDTO selectMineInfoDTO(String t_id);
}
